package com.zlq.cn.controller.sign.ai;

import com.baidubce.qianfan.model.chat.ChatRequest;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.baidubce.qianfan.model.completion.CompletionRequest;
import com.baidubce.qianfan.model.completion.CompletionResponse;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.service.ai.QianfanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "百度-千帆")
@Validated
@RestController
@RequestMapping("/qianfan")
public class QianfanController {
    @Resource
    private QianfanService qianfanService;

    @ApiOperation("Chat 对话")
    @PostMapping("/chat/completion")
    public SignApiResult<ChatResponse> chatCompletion(@ApiIgnore @RequestBody ChatRequest chatRequest) {
        return SignApiResult.resultSuccess(qianfanService.chatCompletion(chatRequest));
    }

    @ApiOperation("Completion 续写")
    @PostMapping("/completion")
    public SignApiResult<CompletionResponse> completion(@ApiIgnore @RequestBody CompletionRequest request) {
        return SignApiResult.resultSuccess(qianfanService.completion(request));
    }
}
